#
# Copyright (C) 2009-2014 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=libdbi-drivers
PKG_VERSION:=0.9.0
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/libdbi-drivers
PKG_MD5SUM:=9f47b960e225eede2cdeaabf7d22f59f

PKG_FIXUP:=autoreconf

include $(INCLUDE_DIR)/package.mk

define Package/libdbi-drivers/default
  SECTION:=libs
  CATEGORY:=Libraries
  TITLE:=libdbi-drivers
  URL:=http://libdbi-drivers.sourceforge.net/
endef

define Package/libdbi-drivers/default/description
       libdbi-drivers project provides the database-specific drivers
for the libdbi framework
endef

define Package/libdbi-drivers-mysql
$(call Package/libdbi-drivers/default)
  DEPENDS:=libdbi +PACKAGE_libdbi-drivers-mysql:libmysqlclient
  TITLE:= libdbi-drivers-mysql
endef

define Package/libdbi-drivers-mysql2/description
       libdbi-driver for mysql
endef

define Package/libdbi-drivers-pgsql
$(call Package/libdbi-drivers/default)
  DEPENDS:=libdbi +PACKAGE_libdbi-drivers-pgsql:libpq
  TITLE:= libdbi-drivers-pgsql
endef

define Package/libdbi-drivers-pgsql/description
       libdbi-driver for pgsql
endef

define Package/libdbi-drivers-sqlite2
$(call Package/libdbi-drivers/default)
  DEPENDS:=libdbi +PACKAGE_libdbi-drivers-sqlite2:libsqlite2
  TITLE:= libdbi-drivers-sqlite2
endef

define Package/libdbi-drivers-sqlite2/description
       libdbi-driver for sqlite2
endef

define Package/libdbi-drivers-sqlite3
$(call Package/libdbi-drivers/default)
  DEPENDS:=libdbi +PACKAGE_libdbi-drivers-sqlite3:libsqlite3
  TITLE:= libdbi-drivers-sqlite3
endef

define Package/libdbi-drivers-sqlite3/description
       libdbi-driver for sqlite3
endef

CONFIGURE_ARGS += \
		  --enable-shared \
		  --disable-static \
		  --disable-rpath \
		  --disable-docs \
		  --with-dbi-incdir=$(STAGING_DIR)/usr/include \
		  --with-dbi-libdir=$(STAGING_DIR)/usr/lib

ifneq ($(CONFIG_PACKAGE_libdbi-drivers-mysql),)
CONFIGURE_ARGS += \
		  --with-mysql \
		  --with-mysql-incdir=$(STAGING_DIR)/usr/include/mysql \
		  --with-mysql-libdir=$(STAGING_DIR)/usr/lib/mysql
TARGET_LDFLAGS += \
		  -L$(STAGING_DIR)/usr/lib/mysql/
endif

ifneq ($(SDK)$(CONFIG_PACKAGE_libdbi-drivers-pgsql),)
CONFIGURE_ARGS += \
		  --with-pgsql \
		  --with-pgsql-incdir=$(STAGING_DIR)/usr/include \
		  --with-pgsql-libdir=$(STAGING_DIR)/usr/lib
endif

ifneq ($(SDK)$(CONFIG_PACKAGE_libdbi-drivers-sqlite2),)
CONFIGURE_ARGS += \
		  --with-sqlite \
		  --with-sqlite-incdir=$(STAGING_DIR)/usr/include \
		  --with-sqlite-libdir=$(STAGING_DIR)/usr/lib
endif

ifneq ($(SDK)$(CONFIG_PACKAGE_libdbi-drivers-sqlite3),)
CONFIGURE_ARGS += \
		  --with-sqlite3 \
		  --with-sqlite3-incdir=$(STAGING_DIR)/usr/include \
		  --with-sqlite3-libdir=$(STAGING_DIR)/usr/lib
endif

define Package/libdbi-drivers-mysql/install
	$(INSTALL_DIR) $(1)/usr/lib/dbd
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/drivers/mysql/.libs/libdbdmysql.so $(1)/usr/lib/dbd
endef

define Package/libdbi-drivers-pgsql/install
	$(INSTALL_DIR) $(1)/usr/lib/dbd
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/drivers/pgsql/.libs/libdbdpgsql.so $(1)/usr/lib/dbd
endef

define Package/libdbi-drivers-sqlite2/install
	$(INSTALL_DIR) $(1)/usr/lib/dbd
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/drivers/sqlite/.libs/libdbdsqlite.so $(1)/usr/lib/dbd
endef

define Package/libdbi-drivers-sqlite3/install
	$(INSTALL_DIR) $(1)/usr/lib/dbd
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/drivers/sqlite3/.libs/libdbdsqlite3.so $(1)/usr/lib/dbd
endef


#$(eval $(call BuildPackage,libdbi-drivers))
$(eval $(call BuildPackage,libdbi-drivers-mysql))
$(eval $(call BuildPackage,libdbi-drivers-pgsql))
$(eval $(call BuildPackage,libdbi-drivers-sqlite2))
$(eval $(call BuildPackage,libdbi-drivers-sqlite3))
